package com.zyzo.demo.appengine.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.zyzo.demo.appengine.client.customwidget.user.CustomerCellTable;
import com.zyzo.demo.appengine.client.customwidget.user.CustomerUserCreator.CustomerUserCreator;

public class Gwtclient implements EntryPoint 
{
	private MenuBar menuBar =null;
	private HTMLPanel htmlPanelCenter =null;
	private Widget mainWidget =null;
	
	
	private void switchMainWidget( Widget newWidget )
	{
		if( mainWidget != null )htmlPanelCenter.remove(mainWidget);
		if( newWidget != null )htmlPanelCenter.add(newWidget  );
		mainWidget = newWidget;
	}
	
	@Override
	public void onModuleLoad() 
	{
		final RootPanel rootPanel = RootPanel.get();
		
		menuBar = new MenuBar(false);
		menuBar.setAnimationEnabled(true);
		rootPanel.add(menuBar);
		
		MenuItem mntmDashboard = new MenuItem("Dashboard", false, (Command) null);
		menuBar.addItem(mntmDashboard);
		MenuBar menuBarCatalog = new MenuBar(true);
		
		MenuItem mntmCatalog = new MenuItem("Catalog", false, menuBarCatalog);
		
		MenuItem mntmCategory = new MenuItem("Category", false, new Command() {
			public void execute() 
			{
				CustomerUserCreator cuc = new CustomerUserCreator();
				switchMainWidget(cuc);
			}
		});
		menuBarCatalog.addItem(mntmCategory);
		
		MenuItem mntmProduct = new MenuItem("Product", false, (Command) null);
		menuBarCatalog.addItem(mntmProduct);
		menuBar.addItem(mntmCatalog);
		MenuBar menuBarSales = new MenuBar(true);
		
		MenuItem mntmSales = new MenuItem("Sales", false, menuBarSales);
		
		MenuItem mntmOrders = new MenuItem("Orders", false, (Command) null);
		menuBarSales.addItem(mntmOrders);
		
		MenuItem mntmCustomers = new MenuItem("customers", false, new Command() {
			public void execute() 
			{
				CustomerCellTable ct = new CustomerCellTable();
				switchMainWidget( ct );				
			}
		});
		menuBarSales.addItem(mntmCustomers);
		menuBar.addItem(mntmSales);
		
		htmlPanelCenter = new HTMLPanel("");
		rootPanel.add(htmlPanelCenter);
		htmlPanelCenter.setSize("100%", "100%");
	}
}
